const fp = require('lodash/fp')
const { MayBe, Container } = require('./support')

// 1
let mayBe = MayBe.of([5, 6, 11])
let ex1 = () => {
  return mayBe.map(fp.map(fp.add(1)))
}

console.log(ex1())

// 2
let xs = Container.of(['do', 'ray', 'me', 'fa', 'so', 'la', 'ti', 'do'])

let ex2 = () => {
  return xs.map(fp.first)
}

console.log(ex2())

// 3

let safeProp = fp.curry(function (x, o) {
  return MayBe.of(o[x])
})

let user = { id: 2, name: 'Albert' }

let ex3 = () => {
  return safeProp('name', user).map(fp.first)
}

console.log(ex3())

// 4
let ex4 = function (n) {
  return MayBe.of(n).map(parseInt)
}

console.log(ex4(10.1))